<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
	</head>
	<body>
		<input type="text" id="inputId" />
		<input type="button" value="阶乘" onclick="fact()" /> 
		=
		<span id="inputId2"></span>
	</body>
	
	<style type="text/css"></style>
		<script type="text/javascript">
			function fact(){
				var input1 = document.getElementById("inputId");
				var input2 = document.getElementById("inputId2");
				var q = input1.value;
				var ji = 1;
				if(isNaN(q)){
					input2.innerHTML = "这不是一个数字";
					return;
				}
				if(q < 0){
					input2.innerHTML = "负数没有阶乘";
				}else if (q == 0) {
					input2.innerHTML=1;
				}else{
					for (var i = 0;i < q;i++) {
//					ji = i * ji;
                    ji = ji*(q - i);
//				console.log(ji);
				}
				input2.innerHTML=ji;
				
				}
				
			}
	</script>
</html>
